package org.example.util;

import lombok.ToString;

import java.io.Serializable;

/**
 * 相应页面对象
 */
@ToString
public class ResponseResult implements Serializable {

    //相应业务码
    private String code;
    //响应业务数据
    private Object body;
    //响应消息
    private String msg;
    //响应业务状态
    private boolean success;

    public static ResponseResult build(boolean success,String code, String msg, Object data) {
        return new ResponseResult(success,code,data,msg);
    }

    public static ResponseResult ok(Object data) {
        return new ResponseResult(data);
    }

    public static ResponseResult msgOk(String msg) {
        return new ResponseResult(true,"100",null,msg);
    }

    public static ResponseResult businessError(String msg) {
        return new ResponseResult(false,"101",null,msg);
    }

    public static ResponseResult msgError(String msg) {
        return new ResponseResult(false,"400",null,msg);
    }

    public static ResponseResult createOk() {
        return new ResponseResult(true,"100",null,"新增成功");
    }

    public static ResponseResult saveOk() {
        return new ResponseResult(true,"100",null,"保存成功");
    }



    public static ResponseResult updateOk() {
        return  new ResponseResult(true,"100",null,"修改成功");
    }

    public static ResponseResult deleteOk() {
        return new ResponseResult(true,"100",null,"删除成功");
    }

    public static ResponseResult serverError(String errorMsg) {
        return new ResponseResult(false,"500",null,errorMsg);
    }


    public ResponseResult(boolean success, String code, Object data, String msg) {
        this.success = success;
        this.code = code;
        this.body = data;
        this.msg = msg;
    }

    public ResponseResult() {
    }

    public ResponseResult(Object obj) {
        this.body = obj;
        this.code="100";
        this.success=true;
    }

    @Override
    public String toString() {
        return msg;
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public Object getBody() {
        return body;
    }

    public void setBody(Object body) {
        this.body = body;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public boolean isSuccess() {
        return success;
    }

    public void setSuccess(boolean success) {
        this.success = success;
    }
}

